package cn.gem.rainbow.cfg.web.servlet;

import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * https://mp.weixin.qq.com/s?__biz=MzU3MTAzNTMzMQ==&mid=2247484377&idx=1&sn=a20ce7e5e04ede4dff5fa84a7c5c8448&chksm=fce71875cb9091639124afa69d0ec7bbf8f50438fd7acaf582fb029b7a4adf2f36fa50d4f0fa&token=1748723444&lang=zh_CN#rd
 * <p>
 * 让 Spring 容器来管理我们的Servlet
 */
@Configuration
public class WebServletConfig {

    /**
     * 定义一个ServletRegistrationBean，让它持有 CustomServlet 的实例
     *
     * @return
     */
    @Bean
    public ServletRegistrationBean servletBean() {
        ServletRegistrationBean registrationBean = new ServletRegistrationBean();
        registrationBean.addUrlMappings("/custom");
        registrationBean.setServlet(new CustomServlet());
        return registrationBean;
    }
}
